﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace gg
{
    class TestDateTimeParser
    {
                    //userInput,expected desc,expected tag,expected time, describe test  
        static string[,] tests = new string[,] { 
                {"tmr", DateTime.Parse(DateTime.Now.AddDays(1).ToShortDateString()).ToString(), "tmr test"},
                {"tmr 5pm",DateTime.Parse(DateTime.Now.AddDays(1).ToShortDateString()).AddHours(17).ToString(), "tmr test with time"},
                {"5pm tmr",DateTime.Parse(DateTime.Now.AddDays(1).ToShortDateString()).AddHours(17).ToString(), "tmr test with time swapped"},
                {"tmr 2359",DateTime.Parse(DateTime.Now.AddDays(1).ToShortDateString()).AddHours(23).AddMinutes(59).ToString(), "tmr test with time"},
                {"tmr 5pm", DateTime.Parse(DateTime.Now.AddDays(1).ToShortDateString()).AddHours(17).ToString(), "tmr test with time and tag"},
                {"17/09/2011",DateTime.Parse("09/17/2011").ToString(), "specific date"},
                {"17/09", DateTime.Parse("09/17/2011").ToString(), "short date"},
                {"17-9",  DateTime.Parse("09/17/2011").ToString(), "short date variation"},
                {"17-9 5pm", DateTime.Parse("09/17/2011").AddHours(17).ToString(), "short date and time"},
                {"sun 5pm", DateTime.Parse("10/30/2011").AddHours(17).ToString(), "next week and time"},
                {"11 feb", DateTime.Parse("02/11/2011").ToString(), "natural date"},
                {"oct", DateTime.Parse("10/1/2011").ToString(), "natural month only"},
                {"11 oct 5pm",  DateTime.Parse("10/11/2011").AddHours(17).ToString(), "natural date with time"},
                {" ",  DateTime.MinValue.ToString(), "empty string"},
                {"oct 13 things to do get my things done (((!##$#! 5pm",  DateTime.Parse("10/13/2011").AddHours(17).ToString(), "messy string with time"}
    
        };

        public static void TestQuickParser()
        {

            int passed = 0;

            for (int i = 0; i < (tests.Length / 3); i++)
            {
                testParser(i);
                passed++;
            }
            Console.WriteLine("DateTimeParser passed test cases = " + passed);
        }

        static void testParser(int index)
        {
            string textInput = tests[index, 0];
            DateTime dateTime = DateTimeParser.Parse(tests[index, 0]);
            assert(dateTime.ToString(), tests[index, 1], tests[index, 2] + " datetime");
        }

        static void assert(string expected, string actual, string message)
        {
            if (!expected.Equals(actual))
            {
                Console.WriteLine(string.Format("{0} failed!\n {1} != {2}", message, expected, actual));
                Console.ReadLine();
                Environment.Exit(1);
            }
        }
    }
}
